package com.kfm.am.tcp;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws IOException {
        System.out.println("服务端启动成功,等待连接...");
        ServerSocket serverSocket = new ServerSocket(8888);
        Socket socket = serverSocket.accept();  // 等待客户端连接 接受连接成功的对象
        System.out.println(socket.getInetAddress().getHostAddress() + "创建连接成功");
        InputStream in = socket.getInputStream(); // 获取连接的输入流对象
        byte[] bytes = in.readAllBytes();  // 读取输入流中的数据
        String message = new String(bytes);
        System.out.println(socket.getInetAddress().getHostAddress() + " say " + message);
        in.close();
        socket.close();
        serverSocket.close();

    }
}
